﻿using System;
using System.Collections.Generic;
using System.Web.Services;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Data.SqlClient;
using Adex;
using Telerik.Web.UI;
using MediaMonitor.Common;
using System.Web.Security;
using System.Configuration;
using System.Drawing;
using Telerik.Charting;
using System.Transactions;
using SubSonic;
using System.Net.Mail;
using OfficeOpenXml;
using OfficeOpenXml.Drawing.Chart;
using System.Net;
using System.Text;

namespace MediaMonitor.Users
{
    public partial class NewAll_newsalertPendingMultiMedia : Adex.BasePage
    {
        string appemailPassword = "";
        private static string AppName = ConfigurationManager.AppSettings["AppName"].ToString();
        private static string AdminEmail = ConfigurationManager.AppSettings["AdminEmail"].ToString();
        protected void Page_Load(object sender, EventArgs e)
        {
            string decryptpwd = string.Empty;
            UTF8Encoding encodepwd = new UTF8Encoding();
            Decoder Decode = encodepwd.GetDecoder();
            byte[] todecode_byte = Convert.FromBase64String(Request.Cookies["App"]["Password"].ToString());
            int charCount = Decode.GetCharCount(todecode_byte, 0, todecode_byte.Length);
            char[] decoded_char = new char[charCount];
            Decode.GetChars(todecode_byte, 0, todecode_byte.Length, decoded_char, 0);
            appemailPassword = new String(decoded_char);

            hdnUserID.Value = Request.Cookies["User"]["UserName"].ToString();
            hdnUserName.Value = Request.Cookies["User"]["UserID"].ToString();
            hdnUserRole.Value = Request.Cookies["User"]["UserRole"].ToString();
            if (!IsPostBack)
            {
                loadFirstRadChart();
                loadBindData();
            }
        }
        private void loadFirstRadChart()
        {
            ViewState["Cookie"] = Request.Cookies["User"]["Company"].ToString();

            ViewState["code"] = Request.QueryString["code"].ToString();

            if (Request.QueryString["code"].ToString() != "")
            {

                bindChart(Request.QueryString["code"].ToString());

                DataTable dtToday = SPs.NewsAlertPendingCount(Convert.ToInt32(Request.Cookies["User"]["UserID"].ToString()), Request.Cookies["User"]["Company"].ToString(), ViewState["code"].ToString(), "", "", "", "", "").GetDataSet().Tables[0];
                if (Convert.ToInt32(dtToday.Rows[0][1]) > 0 || Convert.ToInt32(dtToday.Rows[1][1]) > 0 || Convert.ToInt32(dtToday.Rows[2][1]) > 0 || Convert.ToInt32(dtToday.Rows[3][1]) > 0)
                {
                    bool flag;
                    Color[] green = new Color[] { Color.Gray, Color.Green, Color.LightPink, Color.Orange };
                    Color[] barColors = green;
                    RadChart1.Visible = true;
                    this.RadChart1.PlotArea.XAxis.AxisLabel.Visible = false;
                    this.RadChart1.PlotArea.XAxis.AutoScale = false;
                    this.RadChart1.PlotArea.XAxis.AddRange(1, 4, 1);
                    RadChart1.DataSource = dtToday;
                    RadChart1.DataBind();
                    int i = 0;
                    IEnumerator<ChartSeriesItem> enumerator = this.RadChart1.Series[0].Items.GetEnumerator();
                    try
                    {
                        while (true)
                        {
                            flag = enumerator.MoveNext();
                            if (!flag)
                            {
                                break;
                            }
                            ChartSeriesItem item = enumerator.Current;
                            int num = i;
                            i = num + 1;
                            item.Appearance.FillStyle.MainColor = barColors[num];
                        }
                    }
                    finally
                    {
                        flag = enumerator == null;
                        if (!flag)
                        {
                            enumerator.Dispose();
                        }
                    }
                    this.RadChart1.PlotArea.XAxis[0].TextBlock.Text = dtToday.Rows[0][1].ToString();
                    this.RadChart1.PlotArea.XAxis[1].TextBlock.Text = dtToday.Rows[1][1].ToString();
                    this.RadChart1.PlotArea.XAxis[2].TextBlock.Text = dtToday.Rows[2][1].ToString();
                    this.RadChart1.PlotArea.XAxis[3].TextBlock.Text = dtToday.Rows[3][1].ToString();
                    this.RadChart1.Skin = "BlueStripes";
                }
                else { RadChart1.Visible = false; }

            }
            else
            {
                string code = "";
                string count = "";
                if (Request.Cookies["Last"]["TV"] != "" || Request.Cookies["Last"]["Press"] != "" || Request.Cookies["Last"]["Radio"] != "" || Request.Cookies["Last"]["Internet"] != "")
                {

                    if (Request.Cookies["Last"]["TV"] != "" && Request.Cookies["Last"]["TV"] != null)
                    {
                        code += Request.Cookies["Last"]["TV"] + ",";
                        count += "'" + Request.Cookies["Last"]["TV"] + "',";
                    }
                    if (Request.Cookies["Last"]["Press"] != "" && Request.Cookies["Last"]["Press"] != null)
                    {
                        code += Request.Cookies["Last"]["Press"] + ",";
                        count += "'" + Request.Cookies["Last"]["Press"] + "',";
                    }
                    if (Request.Cookies["Last"]["Radio"] != "" && Request.Cookies["Last"]["Radio"] != null)
                    {
                        code += Request.Cookies["Last"]["Radio"] + ",";
                        count += "'" + Request.Cookies["Last"]["Radio"] + "',";
                    }
                    if (Request.Cookies["Last"]["Internet"] != "" && Request.Cookies["Last"]["Internet"] != null)
                    {
                        code += Request.Cookies["Last"]["Internet"];
                        count += "'" + Request.Cookies["Last"]["Internet"] + "',";
                    }
                }
                code = code.TrimEnd(',');
                ViewState["code"] = code;
                bindChart(code);
                DataTable dtToday = SPs.NewsAlertPendingCount(Convert.ToInt32(Request.Cookies["User"]["UserID"].ToString()), Request.Cookies["User"]["Company"].ToString(), "iNMEDIA", Request.Cookies["Last"]["TV"], Request.Cookies["Last"]["Radio"], Request.Cookies["Last"]["Internet"], Request.Cookies["Last"]["Press"], count.TrimEnd(',')).GetDataSet().Tables[0];
                if (Convert.ToInt32(dtToday.Rows[0][1]) > 0 || Convert.ToInt32(dtToday.Rows[1][1]) > 0 || Convert.ToInt32(dtToday.Rows[2][1]) > 0 || Convert.ToInt32(dtToday.Rows[3][1]) > 0)
                {
                    bool flag;
                    Color[] green = new Color[] { Color.Gray, Color.Green, Color.LightPink, Color.Orange };
                    Color[] barColors = green;
                    RadChart1.Visible = true;
                    this.RadChart1.PlotArea.XAxis.AxisLabel.Visible = false;
                    this.RadChart1.PlotArea.XAxis.AutoScale = false;
                    this.RadChart1.PlotArea.XAxis.AddRange(1, 4, 1);
                    RadChart1.DataSource = dtToday;
                    RadChart1.DataBind();
                    int i = 0;
                    IEnumerator<ChartSeriesItem> enumerator = this.RadChart1.Series[0].Items.GetEnumerator();
                    try
                    {
                        while (true)
                        {
                            flag = enumerator.MoveNext();
                            if (!flag)
                            {
                                break;
                            }
                            ChartSeriesItem item = enumerator.Current;
                            int num = i;
                            i = num + 1;
                            item.Appearance.FillStyle.MainColor = barColors[num];
                        }
                    }
                    finally
                    {
                        flag = enumerator == null;
                        if (!flag)
                        {
                            enumerator.Dispose();
                        }
                    }
                    this.RadChart1.PlotArea.XAxis[0].TextBlock.Text = dtToday.Rows[0][1].ToString();
                    this.RadChart1.PlotArea.XAxis[1].TextBlock.Text = dtToday.Rows[1][1].ToString();
                    this.RadChart1.PlotArea.XAxis[2].TextBlock.Text = dtToday.Rows[2][1].ToString();
                    this.RadChart1.PlotArea.XAxis[3].TextBlock.Text = dtToday.Rows[3][1].ToString();
                    this.RadChart1.Skin = "BlueStripes";
                }
                else { RadChart1.Visible = false; }
            }
        }
        private void loadBindData()
        {
            if (Request.Cookies["Last"]["Press"] != null && Request.Cookies["Last"]["Press"] != "")
            {
                Press(Request.Cookies["User"]["UserID"].ToString(), Request.Cookies["User"]["Company"].ToString(), "", "PENDING","","", 0, "", 0);
            }
            if (Request.Cookies["Last"]["TV"] != null && Request.Cookies["Last"]["TV"] != "")
            {
                TV(Request.Cookies["User"]["UserID"].ToString(), Request.Cookies["User"]["Company"].ToString(), "", "PENDING","","", 0, "", 1);
            }
            if (Request.Cookies["Last"]["Radio"] != null && Request.Cookies["Last"]["Radio"] != "")
            {
                Radio(Request.Cookies["User"]["UserID"].ToString(), Request.Cookies["User"]["Company"].ToString(), "", "PENDING","","", 0, "", 2);
            }
            if (Request.Cookies["Last"]["Internet"] != null && Request.Cookies["Last"]["Internet"] != "")
            {
                Internet(Request.Cookies["User"]["UserID"].ToString(), Request.Cookies["User"]["Company"].ToString(), "", "PENDING","","", 0, "", 3);
            }
        }
        protected void ddlSortNews_SelectedIndexChanged(object sender, EventArgs e)
        {
            string text = this.ddlSortNews.SelectedItem.Text;
            DataTable dt = null;
            ViewState["text"] = text;
            switch (text)
            {


                case "Media Type":
                    dt = SPs.NewaAlertLast(Request.Cookies["User"]["Company"].ToString(), ViewState["code"].ToString(), "MediaTypeName asc", "").GetDataSet().Tables[0];
                    break;
                case "Title":
                    dt = SPs.NewaAlertLast(Request.Cookies["User"]["Company"].ToString(), ViewState["code"].ToString(), "Title asc", "").GetDataSet().Tables[0];
                    break;
                case "Chronological":
                    dt = SPs.NewaAlertLast(Request.Cookies["User"]["Company"].ToString(), ViewState["code"].ToString(), "RFdate asc", "").GetDataSet().Tables[0];
                    break;
                case "Most Recent":
                    dt = SPs.NewaAlertLast(Request.Cookies["User"]["Company"].ToString(), ViewState["code"].ToString(), "RFDate desc", "").GetDataSet().Tables[0];
                    break;
            }

        }
        public string color(object val)
        {
            string color = "";
            if (val.ToString() == "Positiva")
                color = "class='Positiva'";
            else if (val.ToString() == "Neutra")
                color = "class='Neutra'";
            else if (val.ToString() == "Negativa")
                color = "class='Negativa'";
            return color;

        }
        public string checkComment(string commentCount)
        {
            return (Convert.ToInt32(commentCount) > 0) ? "../images/chat-icon2.png" : "../images/chat-icon.jpg";
        }
        protected void btnSearch_click(object sender, EventArgs e)
        {
            SendMail(txtSendEmail.Text.ToString(), hdnID.Value.ToString(), txtSubject.Text, txtEmailBody.Text, txtSentby.Text);
            addressBook(txtSendEmail.Text.ToString());
            string script = "alert(\"Your news has been shared!\");";
            ScriptManager.RegisterStartupScript(this, this.GetType(), "ServerControlScript", script, true);
           
        }
        private void SendMail(String Users, string ID, string subject, string emailBody, string from)
        {
            string[] str = emailBody.Split(',');
            String msg = str[0] + "<br/>" + char.ToUpper(from[0]) + from.Substring(1) + " " + str[1] + "<br/><br/><br/><a href='" + Utility.AppPath + "/ShareNews.aspx?Code=" + ID + "'>Click here to view</a>";

            String title = subject;
            String toAccount = Users;
            //String toAccount = "niteshguleria@nascenture.com";
            String MyHost = ConfigurationManager.AppSettings["SMTPHost"].ToString();
            String MySMTPPort = ConfigurationManager.AppSettings["SMTPPort"].ToString();
            String MySMTPSSL = ConfigurationManager.AppSettings["SMTPSSL"].ToString();
            String fromAddr = AdminEmail;   //Email Address of Sender
            MailMessage smtpMssg = new MailMessage();
            smtpMssg.From = new MailAddress(fromAddr);
            if (toAccount.Contains(","))
            {
                string[] tos = toAccount.Split(',');
                for (int i = 0; i < tos.Length; i++)
                {
                    if (tos[i] == "," || tos[i] == "")
                    {
                    }
                    else
                    {
                        smtpMssg.To.Add(new MailAddress(tos[i].Replace(",", "")));
                    }
                }
            }
            else
            {
                smtpMssg.To.Add(new MailAddress(toAccount));
            }
            smtpMssg.Subject = title;
            smtpMssg.Body = msg;
            smtpMssg.IsBodyHtml = true;
            System.Net.Mail.SmtpClient smtpClient = new System.Net.Mail.SmtpClient(MyHost, Convert.ToInt32(MySMTPPort));
            smtpClient.Credentials = new NetworkCredential(Request.Cookies["App"]["Email"].ToString(), appemailPassword);
            smtpClient.DeliveryMethod = SmtpDeliveryMethod.Network;
            if (MySMTPSSL == "true")
            {
                smtpClient.EnableSsl = true;
            }

            try
            {
                smtpClient.Send(smtpMssg);
            }
            catch (Exception ex)
            {
                throw new Exception("Email not sent | Reason: [" + ex.Message + "]");
            }
        }
        private void SendmailForVedio(String users, string ID, string link, string subject, string emailBody, string from)
        {
            string[] str = emailBody.Split(',');
            String msg = str[0] + "<br/>" + char.ToUpper(from[0]) + from.Substring(1) + " " + str[1] + "<br/><br/><br/><a href='" + link + "'>Click here to view</a>";

            String title = subject;
            String toAccount = users;
            //String toAccount = "niteshguleria@nascenture.com";
            String MyHost = ConfigurationManager.AppSettings["SMTPHost"].ToString();
            String MySMTPPort = ConfigurationManager.AppSettings["SMTPPort"].ToString();
            String MySMTPSSL = ConfigurationManager.AppSettings["SMTPSSL"].ToString();
            String fromAddr = AdminEmail;   //Email Address of Sender
            MailMessage smtpMssg = new MailMessage();
            smtpMssg.From = new MailAddress(fromAddr);
            if (toAccount.Contains(","))
            {
                string[] tos = toAccount.Split(',');
                for (int i = 0; i < tos.Length; i++)
                {
                    if (tos[i] == "," || tos[i] == "")
                    {
                    }
                    else
                    {
                        smtpMssg.To.Add(new MailAddress(tos[i].Replace(",", "")));
                    }
                }
            }
            else
            {
                smtpMssg.To.Add(new MailAddress(toAccount));
            }
            smtpMssg.Subject = title;
            smtpMssg.Body = msg;
            smtpMssg.IsBodyHtml = true;
            System.Net.Mail.SmtpClient smtpClient = new System.Net.Mail.SmtpClient(MyHost, Convert.ToInt32(MySMTPPort));
            smtpClient.Credentials = new NetworkCredential(Request.Cookies["App"]["Email"].ToString(), appemailPassword);
            smtpClient.DeliveryMethod = SmtpDeliveryMethod.Network;
            if (MySMTPSSL == "true")
            {
                smtpClient.EnableSsl = true;
            }

            try
            {
                smtpClient.Send(smtpMssg);
            }
            catch (Exception ex)
            {
                throw new Exception("Email not sent | Reason: [" + ex.Message + "]");
            }

        }
        public void addressBook(string email)
        {
            TransactionOptions options = new TransactionOptions();
            options.Timeout = new TimeSpan(0, 2, 0);
            options.IsolationLevel = System.Transactions.IsolationLevel.ReadUncommitted;
            TransactionScope ts = new TransactionScope(TransactionScopeOption.Suppress, options);
            try
            {
                SharedDbConnectionScope conn = new SharedDbConnectionScope(ConfigurationManager.ConnectionStrings["DBAdex"].ToString());
                try
                {
                    try
                    {

                        TblAddressbok prLog = new TblAddressbok();
                        prLog.EmailID = email;
                        //prLog.UserID = UID;

                        prLog.Save();

                        ts.Complete();


                    }
                    catch (Exception exception)
                    {
                        // ex2 = exception;
                        ts.Dispose();
                        conn.Dispose();
                    }
                }
                finally
                {

                    ((IDisposable)conn).Dispose();

                }
            }
            finally
            {

                ((IDisposable)ts).Dispose();

            }

        }
        protected void btnComment_click(object sender, EventArgs e)
        {
            TransactionOptions options = new TransactionOptions();
            options.Timeout = new TimeSpan(0, 2, 0);
            options.IsolationLevel = System.Transactions.IsolationLevel.ReadUncommitted;
            TransactionScope ts = new TransactionScope(TransactionScopeOption.Suppress, options);
            try
            {
                SharedDbConnectionScope conn = new SharedDbConnectionScope(ConfigurationManager.ConnectionStrings["DBAdex"].ToString());
                try
                {
                    try
                    {

                        if (hdncomentEditID.Value == "0")
                        {
                            TblComment prLog = new TblComment();
                            prLog.NewsID = new int?(Convert.ToInt32(hdnComentID.Value));
                            prLog.Comments = txtComent.Text;
                            prLog.RFDate = new DateTime?(DateTime.Now);
                            prLog.UserID = new int?(Convert.ToInt32(this.Request.Cookies["User"]["UserID"].ToString()));

                            prLog.Save();


                        }
                        else
                        {
                            TblComment.update(Convert.ToInt32(hdncomentEditID.Value), txtComent.Text, Convert.ToInt32(hdnComentID.Value));
                            hdncomentEditID.Value = "0";
                        }
                        ts.Complete();
                        txtComent.Text = string.Empty;

                    }
                    catch (Exception exception)
                    {
                        // ex2 = exception;
                        ts.Dispose();
                        conn.Dispose();
                    }
                }
                finally
                {

                    ((IDisposable)conn).Dispose();

                }
            }
            finally
            {

                ((IDisposable)ts).Dispose();

            }
            if (ViewState["calification"] == null)
                ViewState["calification"] = "";
            if (ViewState["text"] == null)
                ViewState["text"] = "";

            //DataTable dt = SPs.NewaAlertLast(Request.Cookies["User"]["Company"].ToString(), ViewState["code"].ToString(), ViewState["text"].ToString(), ViewState["calification"].ToString()).GetDataSet().Tables[0];
            // RadListView1.DataSource = dt;
            //RadListView1.DataBind();
        }
        protected void imgbtnShareVideo1_click(object sender, EventArgs e)
        {
            string link = "";
            switch (hdnMediaTypeName.Value)
            {
                case "TV":
                    link = Utility.AppPath + "/sitefiles/NewsAlertvideo.aspx?SectionCode=" + hdnSectionCode.Value + "&t=f&ID=" + hdnShareVedioID.Value.Trim();

                    break;
                case "Radio":
                    link = Utility.AppPath + "/sitefiles/NewsAlertradio.aspx?SectionCode=" + hdnSectionCode.Value + "&t=f&ID=" + hdnShareVedioID.Value.Trim();
                    break;
                case "Press":
                    link = Utility.AppPath + "/sitefiles/NewsAlertpress.aspx?ID=" + hdnShareVedioID.Value + "&t=s&file=" + hdnImageAudioVideoName.Value.Trim();
                    break;
                case "Internet":
                    link = Utility.AppPath + "/sitefiles/Internet.aspx?ID=" + hdnShareVedioID.Value + "&t=s&file=" + hdnImageAudioVideoName.Value.Trim();
                    break;
            }
            SendmailForVedio(txtEmailForShareVideo.Text, hdnShareVedioID.Value, link, txtShareSubject.Text, txtShareEmailBody.Text, txtShareSentBy.Text);
            addressBook(txtEmailForShareVideo.Text.ToString());
            string script = "alert(\"Your clip has been shared!\");";
            ScriptManager.RegisterStartupScript(this, this.GetType(), "ServerControlScript", script, true);
           
            //SendmailForVedio(String users, string ID, string link);
        }
        protected void btnCALIFICACIONSave_click(object sender, EventArgs e)
        {
            TblComment.updateNewsCalificación(Convert.ToInt32(hdnlblCalification.Value), ddlCALIFICACION.SelectedItem.Text, "");
            string script = "myFunction('" + hdnlblCalification.Value + "','" + ddlCALIFICACION.SelectedItem.Text + "');";
            ScriptManager.RegisterStartupScript(this, this.GetType(), "ServerControlScript", script, true);
        }
        protected void btnIMPORTANCIASave_click(object sender, EventArgs e)
        {
            TblComment.updateNewsCalificación(Convert.ToInt32(hdnlblCalification.Value), "", ddlIMPORTANCIA.SelectedItem.Text);
            string script = "myFunction1('" + hdnlblCalification.Value + "','" + ddlIMPORTANCIA.SelectedItem.Text + "');";
            ScriptManager.RegisterStartupScript(this, this.GetType(), "ServerControlScript", script, true);
        }
        [WebMethod]
        public static Bind[] GetNames(string IDN)
        {
            DataTable dt = SPs.getReportComment(IDN.ToString()).GetDataSet().Tables[0];
            List<Bind> list = new List<Bind>();

            foreach (DataRow row in dt.Rows)
            {
                Bind _names = new Bind();
                _names.ID = row["ID"].ToString();
                _names.Comments = row["Comments"].ToString();
                _names.NewsID = row["NewsID"].ToString();
                _names.RFDate = Convert.ToDateTime(row["RFDate"].ToString()).ToShortDateString();
                _names.UserID = row["UserID"].ToString();
                _names.FullName = row["FullName"].ToString();
                _names.time = Convert.ToDateTime(row["RFDate"].ToString()).ToShortTimeString();
                list.Add(_names);
            }
            return list.ToArray();
        }
        [WebMethod]
        public static newsalertpopup[] getNewsAlert(string ID)
        {
            DataTable dt = SPs.GetNewsAlertById(Convert.ToInt32(ID.ToString())).GetDataSet().Tables[0];
            List<newsalertpopup> list = new List<newsalertpopup>();

            foreach (DataRow row in dt.Rows)
            {
                newsalertpopup _names = new newsalertpopup();
                _names.ID = row["ID"].ToString();
                _names.MediaTypeName = row["MediaTypeName"].ToString();
                _names.MediaName = row["MediaName"].ToString();
                _names.RFDate = row["RFDate"].ToString();
                _names.MediaTypeCode = row["MediaTypeCode"].ToString();
                _names.MediaDescription = row["MediaDescription"].ToString();
                _names.MediaCode = row["MediaCode"].ToString();
                _names.SectionCode = row["SectionCode"].ToString();
                _names.SectionDescription = row["SectionDescription"].ToString();
                _names.PageorHour = row["PageorHour"].ToString();
                _names.Duration = row["Duration"].ToString();
                _names.Advertiser = row["Advertiser"].ToString();
                _names.Title = row["Title"].ToString();
                _names.Calification = row["Calification"].ToString();
                _names.Important = row["Important"].ToString();
                _names.NewsSummary = row["NewsSummary"].ToString();
                _names.OthersBrandsDnvolved = row["OthersBrandsDnvolved"].ToString();
                _names.OthersPeoplesInvolved = row["OthersPeoplesInvolved"].ToString();
                _names.Link = row["Link"].ToString();
                _names.ImageAudioVideoName = row["ImageAudioVideoName"].ToString();
                _names.News = row["News"].ToString();
                _names.Company = row["Company"].ToString();
                _names.Totalrecord = row["Totalrecord"].ToString();
                list.Add(_names);
            }
            return list.ToArray();
        }
        [WebMethod]
        public static void Insert(int ID, string cal, string imp)
        {
            TblComment.updateNewsCalificación(ID, cal, imp);

        }
        [WebMethod]
        public static void delete(int id)
        {

            try
            {
                TblComment.Delete(id);
            }
            catch
            {
                //AjaxFuncs.MsgBox( page,"Failed to delete this record, because related data (child records) exists in other tables");
            }
        }
        [WebMethod]
        public static Bind1[] GetNames1(string IDN)
        {
            DataTable dt = SPs.Configuración(Convert.ToInt32(IDN.ToString())).GetDataSet().Tables[0];

            List<Bind1> list = new List<Bind1>();

            foreach (DataRow row in dt.Rows)
            {
                Bind1 _names = new Bind1();
                _names.ID = row["ID"].ToString();

                _names.Page = row["Page"].ToString();
                _names.RFDate = Convert.ToDateTime(row["Date"].ToString()).ToShortDateString();
                _names.UserID = row["UserID"].ToString();
                _names.IsActive = Convert.ToInt32(row["Design"].ToString());

                list.Add(_names);
            }
            return list.ToArray();
        }
        [WebMethod]
        public static newsalertpopup[] getmultiScroll(string ID, string code, string click)
        {
            DataTable dt = SPs.GetReportNewsAlertMultiMediaPending(HttpContext.Current.Request.Cookies["User"]["UserID"].ToString(), HttpContext.Current.Request.Cookies["User"]["Company"].ToString(), "", code,"","", Convert.ToInt32(ID), click).GetDataSet().Tables[0];
            List<newsalertpopup> list = new List<newsalertpopup>();

            foreach (DataRow row in dt.Rows)
            {
                newsalertpopup _names = new newsalertpopup();
                _names.ID = row["ID"].ToString();
                _names.MediaTypeName = row["MediaTypeName"].ToString();
                _names.MediaName = row["MediaName"].ToString();
                _names.RFDate = Convert.ToDateTime(row["RFDate"].ToString()).ToShortDateString();
                _names.MediaTypeCode = row["MediaTypeCode"].ToString();
                _names.MediaDescription = row["MediaDescription"].ToString();
                _names.MediaCode = row["MediaCode"].ToString();
                _names.SectionCode = row["SectionCode"].ToString();
                _names.SectionDescription = row["SectionDescription"].ToString();
                _names.PageorHour = row["PageorHour"].ToString();
                _names.Duration = row["Duration"].ToString();
                _names.Advertiser = row["Advertiser"].ToString();
                _names.Title = row["Title"].ToString();
                _names.Calification = row["Calification"].ToString();
                _names.Important = row["Important"].ToString();
                _names.NewsSummary = row["NewsSummary"].ToString();
                _names.OthersBrandsDnvolved = row["OthersBrandsDnvolved"].ToString();
                _names.OthersPeoplesInvolved = row["OthersPeoplesInvolved"].ToString();
                _names.Link = row["Link"].ToString();
                _names.ImageAudioVideoName = row["ImageAudioVideoName"].ToString();
                _names.News = row["News"].ToString();
                _names.Company = row["Company"].ToString();
                _names.Totalrecord = row["Totalrecord"].ToString();
                list.Add(_names);
            }
            return list.ToArray();
        }
        public void bindChart(string code)
        {
            bool flag;
            Color[] green = new Color[] { Color.Green, Color.Red, Color.Blue };
            Color[] barColors = green;
            DataTable dt = SPs.NewsalertPendingCalificacion(Convert.ToInt32(Request.Cookies["User"]["UserID"].ToString()), Request.Cookies["User"]["Company"].ToString(), code).GetDataSet().Tables[0];
            ChartAvenueReport.DataSource = dt;
            ChartAvenueReport.DataBind();
            ViewState["dt11"] = dt;
            flag = (!(dt.Rows[0][1].ToString() == "0") || !(dt.Rows[1][1].ToString() == "0") ? true : !(dt.Rows[2][1].ToString() == "0"));
            bool flag1 = flag;
            if (!flag1)
            {
                this.ChartAvenueReport.Visible = false;
            }
            this.ChartAvenueReport.PlotArea.XAxis.AxisLabel.Visible = false;
            int i = 0;
            this.ChartAvenueReport.PlotArea.XAxis.AutoScale = false;
            this.ChartAvenueReport.PlotArea.XAxis.AddRange(1, 3, 1);
            IEnumerator<ChartSeriesItem> enumerator = this.ChartAvenueReport.Series[0].Items.GetEnumerator();
            try
            {
                while (true)
                {
                    flag1 = enumerator.MoveNext();
                    if (!flag1)
                    {
                        break;
                    }
                    ChartSeriesItem item = enumerator.Current;
                    int num = i;
                    i = num + 1;
                    item.Appearance.FillStyle.MainColor = barColors[num];
                }
            }
            finally
            {
                flag1 = enumerator == null;
                if (!flag1)
                {
                    enumerator.Dispose();
                }
            }
            this.ChartAvenueReport.PlotArea.XAxis[0].TextBlock.Text = dt.Rows[0][1].ToString();
            this.ChartAvenueReport.PlotArea.XAxis[1].TextBlock.Text = dt.Rows[1][1].ToString();
            this.ChartAvenueReport.PlotArea.XAxis[2].TextBlock.Text = dt.Rows[2][1].ToString();
            this.ChartAvenueReport.Skin = "DeepGreen";
        }
        private void Press(string UserID, string Company, string date, string code, string MediaTypeName,string Calification, int ID, string click, int TableIndex)
        {
            DataTable dt = SPs.GetReportNewsAlertMultiMediaPending(UserID, Company, date, code,MediaTypeName,Calification, ID, click).GetDataSet().Tables[TableIndex];
            if (dt.Rows.Count > 0)
            {
                for (int i = 1; i <= dt.Rows.Count; i++)
                {
                    if (i == 1)
                    {
                        PressAlreadyRead.Visible = true;
                        HdnPressAlreadyRead.Value = dt.Rows[i - 1]["ID"].ToString();
                        ltrPressAlreadyRead.Text = "<h2>Press - <small></small></h2><div class='press-data'><h5></h5> <div class='info'></div></div>";
                    }
                    if (i == 1)
                    {
                        PressCurrent.Visible = true;
                        hdnPressCurrent.Value = dt.Rows[i - 1]["ID"].ToString();
                        ltrPressCurrent.Text = " <h2>Press- <small>" +
                                                    Convert.ToDateTime(dt.Rows[i - 1]["RFDate"]).ToShortDateString() + "</small></h2>" +
                                            "<div class=\"press-data\">" +
                                              "<h5><a class='topopup4' style='cursor:pointer' val='" + dt.Rows[i - 1]["ID"] + "'>"
                                                    + dt.Rows[i - 1]["Title"] + "</a></h5>" +
                                                "<div class=\"info\">" +
                                                    "<p>" +
                                                        "<b>Fecha:</b>" +
                                                        Convert.ToDateTime(dt.Rows[i - 1]["RFDate"]).ToShortDateString() + "</p>" +
                                                    "<p>" +
                                                        "<b>Medio:</b><span class=\"blue-color\">" +
                                                            dt.Rows[i - 1]["MediaName"] +
                                                        "</span>" +
                                                    "</p>" +
                                                    "<p>" +
                                                        "<b>Pagina:</b>" +
                                                        dt.Rows[i - 1]["PageorHour"] + "</p>" +
                                                    "<p>" +
                                                        "<b>Seccion:</b> <span>" +
                                                            dt.Rows[i - 1]["SectionDescription"] + "</span></p>" +
                                                "</div>" +
                                                "<div class=\"press-detail\" id='IDPress-" + dt.Rows[i - 1]["ID"] + "'>" +
                                                    "<p>" +
                                                        dt.Rows[i - 1]["NewsSummary"] + "</p>" +
                                                "</div>" +
                                                "<div class=\"press-detail\" style=\"display: none;\" id='IDPressText-" + dt.Rows[i - 1]["ID"] + "'>" +
                                                    "<p>" +
                                                        dt.Rows[i - 1]["News"] + "</p>" +
                                                "</div>" +
                                            "</div>" +
                                            "<div class=\"button-div\">" +
                                        "<div class=\"button-div-text\">" +
                                                    "<p>" +
                                                        "<a href=\"javascript:void(0);\"  class=\"topopup5\" val='" + dt.Rows[i - 1]["ID"] + "'>Calificación:</a>" +
                                                         "<span id=\"spnCalificación-" + dt.Rows[i - 1]["ID"] + "\"> <b " + color(dt.Rows[i - 1]["Calification"]) + ">" +
                                                            dt.Rows[i - 1]["Calification"] + "</b></span>" +
                                                        

                                                        "</p>" +
                                                    "<p>" +
                                                         "<a href=\"javascript:void(0);\" class=\"topopup6\" val='" + dt.Rows[i - 1]["ID"] + "'>Importancia:</a>" +
                                                          "<span id=\"spnImportancia-" + dt.Rows[i - 1]["ID"] + "\"> " + dt.Rows[i - 1]["Important"] + " </span>" +
                                                         
                                                       
                                                          "</p>" +
                                                "</div>" +
                                                "<div class=\"button\">" +
                                                    "<a href=\"#\" val='" + dt.Rows[i - 1]["ID"] + "' class=\"topopup4\" title=\"Read More\">" +
                                                        "<img src=\"../images/icon.jpg\">" +
                                                    "</a><a title=\"Share News\" href=\"#\" class=\"topopup\" val='" + dt.Rows[i - 1]["ID"] + "' subject='" + dt.Rows[i - 1]["Title"] + "' SentBy='" + Request.Cookies["User"]["UserName"] + "'>" +
                                                        "<img src=\"../images/icon1.jpg\"></a> </a> <a title='Comments " + dt.Rows[i - 1]["Totalrecord"] + "' href=\"#\" class=\"topopup2\"" +
                                                            "val='" + dt.Rows[i - 1]["ID"] + "'>" +
                                                            "<img src='" + checkComment(dt.Rows[i - 1]["Totalrecord"].ToString()) + "'>" +
                                                            "</a><a title=\"View\" href=\"javascript:void(0);\" onclick=\"PopupCenterWithScroll('../sitefiles/NewsAlertpress.aspx?ID=" + dt.Rows[i - 1]["ID"] + "&t=s&file=" + dt.Rows[i - 1]["ImageAudioVideoName"] + "', '_blank', 750, 700); \">" +
                                                            "<img src=\"../images/view-icon.jpg\"></a><a title=\"Share Image\" href=\"#\" class=\"topopup3\"" +
                                                                "val='" + dt.Rows[i - 1]["ID"] + "' sectioncode='" + dt.Rows[i - 1]["SectionCode"] + "' mediatypename='" + dt.Rows[i - 1]["MediaTypeName"] + "'" +
                                                                "imageaudiovideoname=' " + dt.Rows[i - 1]["ImageAudioVideoName"] + "' subject='" + dt.Rows[i - 1]["Title"] + "' SentBy='" + Request.Cookies["User"]["UserName"] + "'><img alt=\"Share Vedio\"" +
                                                                    "src=\"../images/share-video.jpg\" />" +
                                                            "</a> <a  title='Download' onclick='javascript:GetDownload(\"" + dt.Rows[i - 1]["ID"] + "\", \"press\"); return false;' href=\"javascript:void(0);\"" +
                                    "style='display: " + dt.Rows[i - 1]["MediaTypeCode"].ToString() + " == \"6\" ? \"inline\" : \"none\"  '>" +
                                   " <img " +
                                        "src=\"../images/download.jpg\" /></a>" +
                                                "</div>" +
                                            "</div>";
                    }
                    if (i == 2)
                    {
                        PressNext.Visible = true;
                        hdnPressNext.Value = dt.Rows[i - 1]["ID"].ToString();
                        ltrPressNext.Text = "<h2>Press - <small>" + Convert.ToDateTime(dt.Rows[i - 1]["RFDate"]).ToShortDateString() + "</small></h2> <div class='press-data'><h5>" + dt.Rows[i - 1]["Title"].ToString() + "</h5> <div class='info'><p><b>Fecha:</b> " + Convert.ToDateTime(dt.Rows[i - 1]["RFDate"]).ToShortDateString() + "</p><p><b>Medio:</b><span class='blue-color'> " + dt.Rows[i - 1]["MediaName"].ToString() + "</span></p><p></div></div>";
                    }
                    if (i < 2)
                    {
                        PressNext.Visible = true;
                        ltrPressNext.Text = "<h2>Press-<small></small></h2><div class='press-data'><h5></h5> <div class='info'></div></div>";
                    }
                }
            }
        }
        private void TV(string UserID, string Company, string date, string code, string MediaTypeName, string Calification, int ID, string click, int TableIndex)
        {
            DataTable dtTV = SPs.GetReportNewsAlertMultiMediaPending(UserID, Company, date, code,MediaTypeName,Calification, ID, click).GetDataSet().Tables[TableIndex];
            if (dtTV.Rows.Count > 0)
            {
                for (int i = 1; i <= dtTV.Rows.Count; i++)
                {
                    if (i == 1)
                    {
                        TVAlreadyRead.Visible = true;
                        hdnTVAlreadyRead.Value = dtTV.Rows[i - 1]["ID"].ToString();
                        ltrTVAlreadyRead.Text = "<h2>TV -<small></small></h2><div class='press-data'><h5></h5> <div class='info'></div></div>";
                    }
                    if (i == 1)
                    {
                        TVCurrent.Visible = true;
                        hdnTVCurrent.Value = dtTV.Rows[i - 1]["ID"].ToString();
                        ltrTVCurrent.Text = "  <h2>TV- <small>" +
                                                    Convert.ToDateTime(dtTV.Rows[i - 1]["RFDate"]).ToShortDateString() + "</small></h2>" +
                                            "<div class=\"press-data\">" +
                                                 "<h5><a class='topopup4' style='cursor:pointer' val='" + dtTV.Rows[i - 1]["ID"] + "'>"
                                                    + dtTV.Rows[i - 1]["Title"] + "</a></h5>" +
                                                "<div class=\"info\">" +
                                                    "<p>" +
                                                        "<b>Fecha:</b>" +
                                                       Convert.ToDateTime(dtTV.Rows[i - 1]["RFDate"]).ToShortDateString() + "</p>" +
                                                    "<p>" +
                                                        "<b>Medio:</b><span class=\"blue-color\">" +
                                                            dtTV.Rows[i - 1]["MediaName"] +
                                                        "</span>" +
                                                    "</p>" +
                                                    "<p>" +
                                                        "<b>Hora:</b>" +
                                                        dtTV.Rows[i - 1]["PageorHour"] + "</p>" +
                                                    "<p>" +
                                                        "<b>Seccion:</b> <span>" +
                                                            dtTV.Rows[i - 1]["SectionDescription"] + "'</span></p>" +
                                                             "<p>" +
                                                        "<b>Duracion:</b> <span>" +
                                                            dtTV.Rows[i - 1]["Duration"] + "</span></p>" +
                                                "</div>" +
                                                "<div class=\"press-detail\" id='IDTV-" + dtTV.Rows[i - 1]["ID"] + "'>" +
                                                    "<p>" +
                                                        dtTV.Rows[i - 1]["NewsSummary"] + "</p>" +
                                                "</div>" +
                                                "<div class=\"press-detail\" style=\"display: none;\" id='IDTVText-" + dtTV.Rows[i - 1]["ID"] + "'>" +
                                                    "<p>" +
                                                        dtTV.Rows[i - 1]["News"] + "</p>" +
                                                "</div>" +
                                            "</div>" +
                                            "<div class=\"button-div\">" +
                                                "<div class=\"button-div-text\">" +
                                                    "<p>" +
                                                        "<a href=\"javascript:void(0);\"  class=\"topopup5\" val='" + dtTV.Rows[i - 1]["ID"] + "'>Calificación:</a>" +
                                                         "<span id=\"spnCalificación-" + dtTV.Rows[i - 1]["ID"] + "\"> <b " + color(dtTV.Rows[i - 1]["Calification"]) + ">" +
                                                            dtTV.Rows[i - 1]["Calification"] + "</b></span>" +
                                                      

                                                        "</p>" +
                                                    "<p>" +
                                                         "<a href=\"javascript:void(0);\" class=\"topopup6\" val='" + dtTV.Rows[i - 1]["ID"] + "'>Importancia:</a>" +
                                                         "<span id=\"spnImportancia-" + dtTV.Rows[i - 1]["ID"] + "\"> " + dtTV.Rows[i - 1]["Important"] + " </span>" +
                                                        
                                                        "</div>" +

                                                           "</p>" +
                                                "</div>" +
                                                "<div class=\"button\">" +
                                                    "<a href=\"#\" val='" + dtTV.Rows[i - 1]["ID"] + "' class=\"topopup4\" title=\"Read More\">" +
                                                        "<img src=\"../images/icon.jpg\">" +
                                                    "</a><a title=\"Share News\" href=\"#\" class=\"topopup\" val='" + dtTV.Rows[i - 1]["ID"] + "' subject='" + dtTV.Rows[i - 1]["Title"] + "' SentBy='" + Request.Cookies["User"]["UserName"] + "'>" +
                                                        "<img src=\"../images/icon1.jpg\"></a> <a href=\"#\" class=\"topopup2\" val='" + dtTV.Rows[i - 1]["ID"] + "'" +
                                                            "title='Comments " + dtTV.Rows[i - 1]["Totalrecord"] + "'>" +
                                                           "<img src='" + checkComment(dtTV.Rows[i - 1]["Totalrecord"].ToString()) + "'>" +
                                                        "</a>" +

                                                        "<a title=\"watch video\" href=\"javascript:void(0);\" onclick=\"PopupCenter('../sitefiles/NewsAlertvideo.aspx?SectionCode=" + dtTV.Rows[i - 1]["SectionCode"] + "&t=f&ID=" + dtTV.Rows[i - 1]["ID"] + "', '_blank', 350, 280); \"" +
                                                            "style='display: " + dtTV.Rows[i - 1]["MediaTypeCode"].ToString() + " == \"1\" ? \"inline\" : \"none\"  %>'>" +
                                                            "<img src=\"../images/view-icon.jpg\">" +
                                                        "</a>" +



                                                        "<a title=\"Share Video\" href=\"#\" class=\"topopup3\" val='" + dtTV.Rows[i - 1]["ID"] + "'" +
                                                            "sectioncode='" + dtTV.Rows[i - 1]["SectionCode"] + "' mediatypename='" + dtTV.Rows[i - 1]["MediaTypeName"] + "'" +
                                                            "imageaudiovideoname=' " + dtTV.Rows[i - 1]["ImageAudioVideoName"] + "' subject='" + dtTV.Rows[i - 1]["Title"] + "' SentBy='" + Request.Cookies["User"]["UserName"] + "'>" +
                                                            "<img alt=\"Share Vedio\" src=\"../images/share-video.jpg\" />" +
                                                        "</a> <a title='Download' onclick='javascript:GetDownload(\"" + dtTV.Rows[i - 1]["ID"] + "\", \"tv\"); return false;' href=\"javascript:void(0);\"" +
                                    "style='display: " + dtTV.Rows[i - 1]["MediaTypeCode"].ToString() + " == \"1\" ? \"inline\" : \"none\"  '>" +
                                    "<img " +
                                        "src=\"../images/download.jpg\" /></a>" +
                                                "</div>" +
                                            "</div>";
                    }
                    if (i == 2)
                    {
                        TVNext.Visible = true;
                        hdnTVNext.Value = dtTV.Rows[i - 1]["ID"].ToString();
                        ltrTVNext.Text = "<h2>TV - <small>" + Convert.ToDateTime(dtTV.Rows[i - 1]["RFDate"]).ToShortDateString() + "</small></h2><div class='press-data'><h5>" + dtTV.Rows[i - 1]["Title"].ToString() + "</h5> <div class='info'> <p><b>Fecha:</b> " + Convert.ToDateTime(dtTV.Rows[i - 1]["RFDate"]).ToShortDateString() + "</p><p><b>Medio:</b><span class='blue-color'> " + dtTV.Rows[i - 1]["MediaName"].ToString() + "</span></p><p></div></div>";
                    }
                    if (i < 2)
                    {
                        TVNext.Visible = true;
                        ltrTVNext.Text = "<h2>TV-<small></small></h2><div class='press-data'><h5></h5> <div class='info'></div></div>";
                    }
                }
            }
        }
        private void Radio(string UserID, string Company, string date, string code, string MediaTypeName, string Calification, int ID, string click, int TableIndex)
        {
            DataTable dtRadio = SPs.GetReportNewsAlertMultiMediaPending(UserID, Company, date, code,MediaTypeName,Calification, ID, click).GetDataSet().Tables[TableIndex];
            if (dtRadio.Rows.Count > 0)
            {
                for (int i = 1; i <= dtRadio.Rows.Count; i++)
                {
                    if (i == 1)
                    {
                        RadioAlreadyRead.Visible = true;
                        hdnRadioAlreadyRead.Value = dtRadio.Rows[i - 1]["ID"].ToString();
                        ltrRadioAlreadyRead.Text = " <h2>Radio -<small></small></h2><div class='press-data'><h5></h5> <div class='info'></div></div>";
                    }
                    if (i == 1)
                    {
                        RadioCurrent.Visible = true;
                        hdnRadioCurrent.Value = dtRadio.Rows[i - 1]["ID"].ToString();
                        ltrRadioCurrent.Text = "    <h2>Radio" +

                                                 "- <small>" +
                                                     Convert.ToDateTime(dtRadio.Rows[i - 1]["RFDate"]).ToShortDateString() + "</small></h2>" +
                                             "<div class=\"press-data\">" +
                                                 "<h5><a class='topopup4' style='cursor:pointer' val='" + dtRadio.Rows[i - 1]["ID"] + "'>"
                                                    + dtRadio.Rows[i - 1]["Title"] + "</a></h5>" +
                                                 "<div class=\"info\">" +
                                                     "<p>" +
                                                         "<b>Fecha:</b>" +
                                                         Convert.ToDateTime(dtRadio.Rows[i - 1]["RFDate"]).ToShortDateString() + "</p>" +
                                                     "<p>" +
                                                         "<b>Medio:</b><span class=\"blue-color\">" +
                                                             dtRadio.Rows[i - 1]["MediaName"] +
                                                         "</span>" +
                                                     "</p>" +
                                                     "<p>" +
                                                         "<b>Hora:</b>" +
                                                         dtRadio.Rows[i - 1]["PageorHour"] + "</p>" +
                                                     "<p>" +
                                                         "<b>Seccion:</b> <span>" +
                                                             dtRadio.Rows[i - 1]["SectionDescription"] + "</span></p>" +
                                                             "<p> <b>Duracion:</b> <span>" +
                                                             dtRadio.Rows[i - 1]["Duration"] + "</span></p>" +
                                                 "</div>" +
                                                 "<div class=\"press-detail\" id='IDRadio-" + dtRadio.Rows[i - 1]["ID"] + "'>" +
                                                     "<p>" +
                                                         dtRadio.Rows[i - 1]["NewsSummary"] + "</p>" +
                                                 "</div>" +
                                                 "<div class=\"press-detail\" style=\"display: none;\" id='IDRadioText-" + dtRadio.Rows[i - 1]["ID"] + "'>" +
                                                     "<p>" +
                                                         dtRadio.Rows[i - 1]["News"] + "</p>" +
                                                 "</div>" +
                                             "</div>" +
                                             "<div class=\"button-div\">" +
                                               "<div class=\"button-div-text\">" +
                                                     "<p>" +
                                                         "<a href=\"javascript:void(0);\"  class=\"topopup5\" val='" + dtRadio.Rows[i - 1]["ID"] + "'>Calificación:</a>" +
                                                          "<span id=\"spnCalificación-" + dtRadio.Rows[i - 1]["ID"] + "\"> <b " + color(dtRadio.Rows[i - 1]["Calification"]) + ">" +
                                                             dtRadio.Rows[i - 1]["Calification"] + "</b></span>" +
                                                        

                                                         "</p>" +
                                                     "<p>" +
                                                          "<a href=\"javascript:void(0);\" class=\"topopup6\" val='" + dtRadio.Rows[i - 1]["ID"] + "'>Importancia:</a>" +
                                                           "<span id=\"spnImportancia-" + dtRadio.Rows[i - 1]["ID"] + "\"> " + dtRadio.Rows[i - 1]["Important"] + " </span>" +
                                                          

                                                           "</p>" +
                                                 "</div>" +
                                                 "<div class=\"button\">" +
                                                     "<a href=\"#\" val='" + dtRadio.Rows[i - 1]["ID"] + "' class=\"topopup4\" title=\"Read More\">" +
                                                         "<img src=\"../images/icon.jpg\">" +
                                                     "</a><a title=\"Share News\" href=\"#\" class=\"topopup\" val='" + dtRadio.Rows[i - 1]["ID"] + "' subject='" + dtRadio.Rows[i - 1]["Title"] + "' SentBy='" + Request.Cookies["User"]["UserName"] + "'>" +
                                                         "<img src=\"../images/icon1.jpg\"></a> <a title='Comments " + dtRadio.Rows[i - 1]["Totalrecord"] + "' href=\"#\" class=\"topopup2\"" +
                                                             "val='" + dtRadio.Rows[i - 1]["ID"] + "'>" +
                                                             "<img src='" + checkComment(dtRadio.Rows[i - 1]["Totalrecord"].ToString()) + "'>" +
                                                         "</a><a title=\"Listen Audio\" href=\"javascript:void(0);\" onclick=\"PopupCenter('../sitefiles/NewsAlertradio.aspx?SectionCode=" + dtRadio.Rows[i - 1]["SectionCode"] + "&t=f&ID=" + dtRadio.Rows[i - 1]["ID"] + "', '_blank', 350, 280); \">" +
                                                             "<img src=\"../images/view-icon.jpg\">" +
                                                         "</a><a title=\"Share Audio\" href=\"#\" class=\"topopup3\" val='" + dtRadio.Rows[i - 1]["ID"] + "'" +
                                                             "sectioncode='" + dtRadio.Rows[i - 1]["SectionCode"] + "' mediatypename='" + dtRadio.Rows[i - 1]["MediaTypeName"] + "'" +
                                                             "imageaudiovideoname='" + dtRadio.Rows[i - 1]["ImageAudioVideoName"] + "' subject='" + dtRadio.Rows[i - 1]["Title"] + "' SentBy='" + Request.Cookies["User"]["UserName"] + "'>" +
                                                             "<img alt=\"share-video\" src=\"../images/share-video.jpg\" />" +
                                                         "</a><a title='Download' onclick='javascript:GetDownload(\"" + dtRadio.Rows[i - 1]["ID"] + "\", \"radio\"); return false;' href=\"javascript:void(0);\"" +
                                     "style='display: " + dtRadio.Rows[i - 1]["MediaTypeCode"].ToString() + " == \"3\" ? \"inline\" : \"none\"  '>" +
                                     "<img " +
                                         "src=\"../images/download.jpg\" /></a>" +
                                                 "</div>" +
                                             "</div>";
                    }
                    if (i == 2)
                    {
                        RadioNext.Visible = true;

                        hdnRadioNext.Value = dtRadio.Rows[i - 1]["ID"].ToString();
                        ltrRadioNext.Text = " <h2>Radio - <small>" + Convert.ToDateTime(dtRadio.Rows[i - 1]["RFDate"]).ToShortDateString() + "</small></h2><div class='press-data'><h5>" + dtRadio.Rows[i - 1]["Title"].ToString() + "</h5> <div class='info'> <p><b>Fecha:</b> " + Convert.ToDateTime(dtRadio.Rows[i - 1]["RFDate"]).ToShortDateString() + "</p><p><b>Medio:</b><span class='blue-color'> " + dtRadio.Rows[i - 1]["MediaName"].ToString() + "</span></p><p></div></div>";
                    }
                    if (i < 2)
                    {
                        RadioNext.Visible = true;
                        ltrRadioNext.Text = "<h2>Radio-<small></small></h2><div class='press-data'><h5></h5> <div class='info'></div></div>";
                    }
                }
            }

        }
        private void Internet(string UserID, string Company, string date, string code, string MediaTypeName, string Calification, int ID, string click, int TableIndex)
        {
            DataTable dtInternet = SPs.GetReportNewsAlertMultiMediaPending(UserID, Company, date, code,MediaTypeName, Calification, ID, click).GetDataSet().Tables[TableIndex];
            if (dtInternet.Rows.Count > 0)
            {
                for (int i = 1; i <= dtInternet.Rows.Count; i++)
                {
                    if (i == 1)
                    {
                        InternetAlreadyRead.Visible = true;
                        hdnInternetAlreadyRead.Value = dtInternet.Rows[i - 1]["ID"].ToString();
                        ltrInternetAlreadyRead.Text = " <h2>Internet-<small></small></h2><div class='press-data'><h5></h5> <div class='info'></div></div>";
                    }
                    if (i == 1)
                    {
                        InternetCurrent.Visible = true;
                        hdnInternetCurrent.Value = dtInternet.Rows[i - 1]["ID"].ToString();
                        ltrInternetCurrent.Text = @"  <h2>
                                                Internet-<small>
                                                    " + Convert.ToDateTime(dtInternet.Rows[i - 1]["RFDate"]).ToShortDateString() + "</small></h2>" +
                                            "<div class=\"press-data\">" +
                                                 "<h5><a class='topopup4' style='cursor:pointer' val='" + dtInternet.Rows[i - 1]["ID"] + "'>"
                                                    + dtInternet.Rows[i - 1]["Title"] + "</a></h5>" +
                                                "<div class=\"info\">" +
                                                   " <p>" +
                                                        "<b>Fecha:</b>" +
                                                        Convert.ToDateTime(dtInternet.Rows[i - 1]["RFDate"]).ToShortDateString() + "</p>" +
                                                    "<p>" +
                                                        "<b>Medio:</b><span class=\"blue-color\">" +
                                                            dtInternet.Rows[i - 1]["MediaName"] +
                                                        "</span>" +
                                                    "</p>" +

                                                        "<b>Seccion:</b> <span>" +
                                                            dtInternet.Rows[i - 1]["SectionDescription"] + "</span></p>" +
                                                "</div>" +
                                                "<div class=\"press-detail\" id='IDInternet-" + dtInternet.Rows[i - 1]["ID"] + "'>" +
                                                    "<p>" +
                                                        dtInternet.Rows[i - 1]["NewsSummary"] + "</p>" +
                                                "</div>" +
                                                "<div class=\"press-detail\" style=\"display: none;\" id='IDInternetText-" + dtInternet.Rows[i - 1]["ID"] + "'>" +
                                                "    <p>" +
                                                        dtInternet.Rows[i - 1]["News"] + "</p>" +
                                                "</div>" +
                                            "</div>" +
                                            "<div class=\"button-div\">" +
                                                   "<div class=\"button-div-text\">" +
                                                    "<p>" +
                                                        "<a href=\"javascript:void(0);\"  class=\"topopup5\" val='" + dtInternet.Rows[i - 1]["ID"] + "'>Calificación:</a>" +
                                                        "<span id=\"spnCalificación-" + dtInternet.Rows[i - 1]["ID"] + "\"> <b " + color(dtInternet.Rows[i - 1]["Calification"]) + ">" +
                                                            dtInternet.Rows[i - 1]["Calification"] + "</b></span>" +
                                                       

                                                         "</p>" +
                                                    "<p>" +
                                                         "<a href=\"javascript:void(0);\" class=\"topopup6\" val='" + dtInternet.Rows[i - 1]["ID"] + "'>Importancia:</a>" +
                                                         "<span id=\"spnImportancia-" + dtInternet.Rows[i - 1]["ID"] + "\"> " + dtInternet.Rows[i - 1]["Important"] + " </span>" +
                                                         
                                                           "</p>" +
                                                "</div>" +
                                                "<div class=\"button\">" +
                                                    "<a href=\"#\" val='" + dtInternet.Rows[i - 1]["ID"] + "' class=\"topopup4\" title=\"Read More\">" +
                                                        "<img src=\"../images/icon.jpg\">" +
                                                    "</a><a title=\"Share News\" href=\"#\" class=\"topopup\" val='" + dtInternet.Rows[i - 1]["ID"] + "' subject='" + dtInternet.Rows[i - 1]["Title"] + "' SentBy='" + Request.Cookies["User"]["UserName"] + "'>" +
                                                        "<img src=\"../images/icon1.jpg\"></a> <a title='Comments " + dtInternet.Rows[i - 1]["Totalrecord"] + "' href=\"#\" class=\"topopup2\"" +
                                                            "val='" + dtInternet.Rows[i - 1]["ID"] + "'>" +
                                                           "<img src='" + checkComment(dtInternet.Rows[i - 1]["Totalrecord"].ToString()) + "'>" +
                                                        "</a><a title=\"View\" href=\"javascript:void(0);\" onclick=\"PopupCenterWithScroll('../sitefiles/Internet.aspx?ID=" + dtInternet.Rows[i - 1]["ID"] + "&t=s&file=" + dtInternet.Rows[i - 1]["ImageAudioVideoName"] + "', '_blank', 750, 700); \">" +
                                                            "<img src=\"../images/view-icon.jpg\"></a><a title=\"Share Image\" href=\"#\" class=\"topopup3\"" +
                                                                "val='" + dtInternet.Rows[i - 1]["ID"] + "' sectioncode='" + dtInternet.Rows[i - 1]["SectionCode"] + "' mediatypename='" + dtInternet.Rows[i - 1]["MediaTypeName"] + "'" +
                                                                "imageaudiovideoname='" + dtInternet.Rows[i - 1]["ImageAudioVideoName"] + "' subject='" + dtInternet.Rows[i - 1]["Title"] + "' SentBy='" + Request.Cookies["User"]["UserName"] + "'><img alt=\"Share Vedio\" src=\"../images/share-video.jpg\" />" +
                                                            "</a><a title='Download' onclick='javascript:GetDownload(\"" + dtInternet.Rows[i - 1]["ID"] + "\", \"Internet\"); return false;'" +
                                        "href=\"javascript:void(0);\" style='display: " + dtInternet.Rows[i - 1]["MediaTypeCode"].ToString() + " == \"9\" ? \"inline\" : \"none\"  '>" +
                                        "<img src=\"../images/download.jpg\" /></a>" +
                                                "</div></div>";
                    }
                    if (i == 2)
                    {
                        InternetNext.Visible = true;
                        hdnInternetNext.Value = dtInternet.Rows[i - 1]["ID"].ToString();
                        ltrInternetNext.Text = " <h2>Internet-<small>" + Convert.ToDateTime(dtInternet.Rows[i - 1]["RFDate"]).ToShortDateString() + "</small></h2><div class='press-data'><h5>" + dtInternet.Rows[i - 1]["Title"].ToString() + "</h5> <div class='info'> <p><b>Fecha:</b> " + Convert.ToDateTime(dtInternet.Rows[i - 1]["RFDate"]).ToShortDateString() + "</p><p><b>Medio:</b><span class='blue-color'> " + dtInternet.Rows[i - 1]["MediaName"].ToString() + "</span></p><p></div></div>";
                    }
                    if (i < 2)
                    {
                        InternetNext.Visible = true;
                        ltrInternetNext.Text = "<h2>Internet-<small></small></h2><div class='press-data'><h5></h5> <div class='info'></div></div>";
                    }
                }
            }
        }
        override protected void OnInit(EventArgs e)
        {
            //
            // CODEGEN: This call is required by the ASP.NET Web Form Designer.
            //
            InitializeComponent();
            InitializeComponent2();
            base.OnInit(e);
        }

        ///        Required method for Designer support - do not modify
        ///        the contents of this method with the code editor.
        /// </summary>
        private void InitializeComponent()
        {
            this.ChartAvenueReport.Click += new Telerik.Web.UI.RadChart.ChartClickEventHandler(this.RadChart1_Click);

        }
        private void InitializeComponent2()
        {
            this.RadChart1.Click += new Telerik.Web.UI.RadChart.ChartClickEventHandler(this.RadChart2_Click);
        }
        private void RadChart2_Click(object sender, ChartClickEventArgs args)
        {
            PressAlreadyRead.Visible = false;
            PressCurrent.Visible = false;
            PressNext.Visible = false;

            TVAlreadyRead.Visible = false;
            TVCurrent.Visible = false;
            TVNext.Visible = false;

            RadioAlreadyRead.Visible = false;
            RadioCurrent.Visible = false;
            RadioNext.Visible = false;

            InternetAlreadyRead.Visible = false;
            InternetCurrent.Visible = false;
            InternetNext.Visible = false;
            if (args.SeriesItem == null)
            {
                loadFirstRadChart();
                loadBindData();
            }
            else
            {
                DataTable dt = SPs.GetReportNewsAlertMultiMediaToday(Convert.ToInt32(Request.Cookies["User"]["UserID"]), Request.Cookies["User"]["Company"].ToString(), DateTime.Now.ToShortDateString() + " 00:00:00.000", "garph", 0, "", "", args.SeriesItem.Name).GetDataSet().Tables[0];
                switch (args.SeriesItem.Name)
                {
                    case "PRESS":
                        Press(Request.Cookies["User"]["UserID"].ToString(), Request.Cookies["User"]["Company"].ToString(), "", "garph", args.SeriesItem.Name,"", 0, "", 0);
                        break;
                    case "TV":
                        TV(Request.Cookies["User"]["UserID"].ToString(), Request.Cookies["User"]["Company"].ToString(), "", "garph", args.SeriesItem.Name, "", 0, "", 0);
                        break;
                    case "RADIO":
                        Radio(Request.Cookies["User"]["UserID"].ToString(), Request.Cookies["User"]["Company"].ToString(), "", "garph", args.SeriesItem.Name, "", 0, "", 0);
                        break;
                    case "INTERNET":
                        Internet(Request.Cookies["User"]["UserID"].ToString(), Request.Cookies["User"]["Company"].ToString(), "", "garph", args.SeriesItem.Name, "", 0, "", 0);
                        break;
                }
            }
        }
        private void RadChart1_Click(object sender, ChartClickEventArgs args)
        {
            Response.Cookies["calificationTodayCookies"].Value = args.SeriesItem.Name;
            PressAlreadyRead.Visible = false;
            PressCurrent.Visible = false;
            PressNext.Visible = false;

            TVAlreadyRead.Visible = false;
            TVCurrent.Visible = false;
            TVNext.Visible = false;

            RadioAlreadyRead.Visible = false;
            RadioCurrent.Visible = false;
            RadioNext.Visible = false;

            InternetAlreadyRead.Visible = false;
            InternetCurrent.Visible = false;
            InternetNext.Visible = false;

            if (args.SeriesItem == null)
            {
                loadFirstRadChart();
                loadBindData();
            }
            else
            {
                //bindChart(ViewState["code"].ToString(), args.SeriesItem.Name);
                Press(Request.Cookies["User"]["UserID"].ToString(), Request.Cookies["User"]["Company"].ToString(), "", "PENDING", "", args.SeriesItem.Name, 0, "", 0);
                TV(Request.Cookies["User"]["UserID"].ToString(), Request.Cookies["User"]["Company"].ToString(), "", "PENDING", "", args.SeriesItem.Name,  0, "", 0);
                Radio(Request.Cookies["User"]["UserID"].ToString(), Request.Cookies["User"]["Company"].ToString(), "", "PENDING", "", args.SeriesItem.Name,  0, "", 0);
                Internet(Request.Cookies["User"]["UserID"].ToString(), Request.Cookies["User"]["Company"].ToString(), "", "PENDING", "", args.SeriesItem.Name, 0, "", 0);
            }
        }
        protected void btnExport_Click(object sender, EventArgs e)
        {
            DataTable dt = SPs.NewaAlertPending(Convert.ToInt32(Request.Cookies["User"]["UserID"].ToString()), Request.Cookies["User"]["Company"].ToString(), "", "Pending", "").GetDataSet().Tables[0];
            ViewState["dt"] = dt;
            DataTable dtDetails = (DataTable)ViewState["dt"];
            if (!dtDetails.Columns.Contains("Date"))
                dtDetails.Columns.Add("Date");
            if (dtDetails.Columns.Contains("RFDate"))
            {
                foreach (DataRow dr in dtDetails.Rows)
                {
                    string date = dr["RFDate"].ToString();
                    dr["Date"] = date.Substring(0, 10);
                    //dr["Date"] = String.Format("{0:dd.MM.yyyy}", dr["RFDate"]);
                }
            }
            if (dtDetails.Columns.Contains("ID"))
            {
                dtDetails.Columns.Remove("ID");
                dtDetails.Columns.Remove("MediaTypeName");
                dtDetails.Columns.Remove("MediaTypeCode");
                dtDetails.Columns.Remove("MediaCode");
                dtDetails.Columns.Remove("SectionCode");
                dtDetails.Columns.Remove("Totalrecord");
              

                dtDetails.Columns.Remove("RFDate");
            }
            DataTable tblcount = (DataTable)ViewState["dt11"];
            DumpSummary(dtDetails, tblcount);
        }

        private void DumpSummary(DataTable tbldetails, DataTable tblChart)
        {

            Int32 tblColumnCount = tbldetails.Columns.Count;
            int row = tbldetails.Rows.Count;
            if (tblColumnCount > 0)
            {

                using (ExcelPackage pck = new ExcelPackage())
                {

                    try
                    {

                        //Create the worksheet
                        ExcelWorksheet ws = pck.Workbook.Worksheets.Add("News&Comments");


                        ws.Cells["A25"].LoadFromDataTable(tblChart, true);
                        ws.Cells["A30"].LoadFromDataTable(tbldetails, true);
                        ws.DefaultColWidth = 20;
                        using (ExcelRange rngSummary = ws.Cells["A1:D1"])
                        {
                            rngSummary.Style.Font.Bold = true;
                        }
                        using (ExcelRange rngUserSelection = ws.Cells["A25:O25"])
                        {
                            rngUserSelection.Style.Font.Bold = true;
                        }
                        var BarChart = ws.Drawings.AddChart("Competition Chart", eChartType.ColumnClustered) as ExcelBarChart;
                        //Set top left corner to row 1 column 2
                        BarChart.SetPosition(3, 2, 2, 2);
                        BarChart.SetSize(800, 400);
                        BarChart.Title.Text = "News & comments calification";
                        BarChart.Style = eChartStyle.Style26;
                        BarChart.Legend.Remove();
                        BarChart.DataLabel.ShowValue = true;
                        BarChart.DataLabel.Font.Bold = true;
                        BarChart.DataLabel.Border.LineCap = OfficeOpenXml.Drawing.eLineCap.Round;
                        BarChart.Series.Add(ExcelRange.GetAddress(26, 2, 28, 2), ExcelRange.GetAddress(26, 1, 28, 1));


                    }
                    catch { }
                    Response.Clear();
                    Response.ContentType = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet";
                    Response.AddHeader("content-disposition", "attachment;  filename=NewsAlert.xlsx");
                    Response.BinaryWrite(pck.GetAsByteArray());
                    Response.End();
                }
            }
        }
    }
}
